package com.ktjy.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
@Component("loggerAspect")
@Aspect
public class LoggerAspect {
    Logger logger = LoggerFactory.getLogger(LoggerAspect.class);

    @Before(value = "execution(* com.ktjy.service..*.*(..))")
    public void before(JoinPoint jp){
        logger.info("【前置增强】 正在调用 {} 的 {}方法。方法入参：{}",jp.getTarget(),
                jp.getSignature().getName(), Arrays.toString(jp.getArgs()));
    }
    @AfterReturning(value = "execution(* com.ktjy.service..*.*(..))",returning = "result")
    public void afterReturning(JoinPoint jp,Object result){
        logger.info("【后置增强】 正在调用 {} 的 {}方法。方法返回值：{}",
                jp.getTarget(), jp.getSignature().getName(), result);
    }

}
